<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.getLists.php');

$aLists = getLists();
if (reqvar('azione')=='gendef') {
	checkDefList($aLists);
	$objSess->setHistoryVar(array('azione'=>''));
}
$sSql = "SELECT tipo_list, cod_list FROM ovf_campi_list "
	." GROUP BY tipo_list, cod_list ";
$objDB->query($sSql,'selTipiList');

$cmdL = "";
$cmdR = "<a href='listIns.php?$sXSNQS' class='cmd1'>nuova lista</a>";
$cmdR .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
$cmdR .= "<a href='listList.php?azione=gendef&$sXSNQS' class='cmd1'>genera liste default</a>";
$cmdR .= cmdTorna(); 

testaHtml('Gestione liste', 'Elenco liste',$msgPag, 'gest');
?>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="lab1" width='10%' align='center'>Tipo lista</td>
      <td class="lab1" width='40%' align='center'>Descrizione</td>
      <td class="lab1" width='50%' align='center'>Codice lista</td>
   </tr>
<? 
$clRF = 'txt2';
$oldTipoList = '';
while($acX = $objDB->fetch('selTipiList')) { 
	$clRF = ($clRF=='txt1')?'txt2':'txt1';	
?>
   <tr>
      <td class="<?=$clRF?>" style='font-family:lucida console,courier;'>
            <?php echo ($oldTipoList == $acX['tipo_list'])?"":$acX['tipo_list'];?>
      </td>
      <td class="<?=$clRF?>">
            <? echo ($oldTipoList == $acX['tipo_list'])?"":ovfVx($aLists, $acX['tipo_list'], 'descr');?>
      </td>
      <td class="<?=$clRF?>">
      	<a href='listMod.php?cod=<?=$acX['cod_list']."&tipo=".$acX['tipo_list']."&$sXSNQS"?>' class="<?=$clRF?>"
      	 	style='font-family:lucida console,courier;'>
            <?
            echo $acX['cod_list'];
            ?>
         </a>
      </td>
<? 
	$oldTipoList = $acX['tipo_list'];
}
 ?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();

function checkDefList($aLists) {
	global $objDB, $objSess;
	foreach($aLists as $list => $aL) {
		$sSql = "SELECT tipo_list,cod_list FROM ovf_campi_list "
			." WHERE tipo_list = '$list' and cod_list = 'default' ";
		$objDB->query($sSql,'selDefList');
		if ($acX=$objDB->fetch('selDefList')) {
			continue;
		}
		foreach($aL['campiDef'] as $seq => $aCD) {
			$sSql = "INSERT INTO ovf_campi_list SET tipo_list = '$list' "
				.", cod_list = 'default' "
				.", seq = ".intval($seq)
				.", label = '".addslashes($aCD[0])."' "
				.", campo = '".addslashes($aCD[1])."' "
				.", campo_size = '".addslashes($aCD[2])."' ";
			$objDB->query($sSql,'selDefList');
		}
	}
}
